package
{
	import com.adobe.crypto.MD5;
	
	import fl.controls.Button;
	import fl.controls.Label;
	import fl.controls.TextInput;
	import fl.events.ComponentEvent;
	import fl.managers.StyleManager;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.system.System;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	[SWF(width=340,height=70)]

	public class FxUploaderTools extends Sprite
	{
		private var qqTxt:TextInput;
		private var md5Txt:TextInput;

		public function FxUploaderTools(){
			initUI();
		}

		private function initUI():void {
			var tf:TextFormat = new TextFormat("Verdana", 12, 0);
			StyleManager.setStyle("textFormat", tf);
			StyleManager.setStyle("disabledTextFormat", tf);
			tabChildren = false;

			var qqLabel:Label = new Label();
			qqLabel.autoSize = TextFieldAutoSize.LEFT;
			qqLabel.text = "　帐号";
			addChild(qqLabel);
			qqLabel.x = 10;
			qqLabel.y = 10;

			var md5Label:Label = new Label();
			md5Label.autoSize = TextFieldAutoSize.LEFT;
			md5Label.text = "认证码";
			addChild(md5Label);
			md5Label.x = 10;
			md5Label.y = 40;

			qqTxt = new TextInput();
			qqTxt.width = 276;
			qqTxt.addEventListener(ComponentEvent.ENTER, qqTextEnterHandler);
			qqTxt.addEventListener(FocusEvent.FOCUS_OUT, qqTextFocusOutHandler);
			addChild(qqTxt);
			qqTxt.x = 54;
			qqTxt.y = 8;

			md5Txt = new TextInput();
			md5Txt.editable = false;
			md5Txt.width = 276;
			md5Txt.addEventListener(ComponentEvent.ENTER, md5TextEnterHandler);
			addChild(md5Txt);
			md5Txt.x = 54;
			md5Txt.y = 38;
		}

		protected function qqTextFocusOutHandler(e:FocusEvent):void {
			md5Txt.text = MD5.hash(qqTxt.text);
			md5Txt.setFocus();
		}

		protected function qqTextEnterHandler(e:ComponentEvent):void {
			md5Txt.text = MD5.hash(qqTxt.text);
			md5Txt.setFocus();
		}

		protected function md5TextEnterHandler(e:ComponentEvent):void {
			System.setClipboard(md5Txt.text);
			ExternalInterface.call("window.alert", "认证码已经复制到剪切板！");
		}
	}
}